from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from ._basic_ import BasicModel
from ._secondary_tables_ import chat_room_user_association, conversation_user_association


class User(BasicModel):
    """
    用户
    """
    __tablename__ = 'users'

    username: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
    """
    用户名
    """

    chat_rooms = relationship(
        'ChatRoom',
        secondary=chat_room_user_association,
        back_populates='users',
    )
    """
    关联的用户列表
    """

    conversations = relationship(
        'Conversation',
        secondary=conversation_user_association,
        back_populates='users',
    )
    """
    关联的用户列表
    """
